package org.tgit.gateway.common;

import java.util.Map;

import net.sf.ehcache.util.concurrent.ConcurrentHashMap;

public class ApiConstants {
	
	public static final String REQ = "REQ";
	public static final String RSP = "RSP";
	public static final String DELIMITER = "===>>";
	public static final String WSDL_FLAG = "wsdlFlag";
	public static final String SEP_PATH = "/";
	public static final String API_MONITOR_DETAIL_BEAN = "apiMonitorDetailBean";
	public static final String REQUEST_URI = "requestURI";
	public static final String DEPLOY_URL = "deployUrl";
	public static final String DEPLOY_URI = "deployUri";
	public static final String ACCESS_URL = "accessUrl";
	public static final String METHOD_GET = "GET";
	public static final String WSDL_LOWER= "wsdl";
	public static final String WSDL_UPPER= "WSDL";
	public static final String API_ID = "apiId";
	public static final String STATUS = "status";
	public static final String ACCESS_TOKEN = "accessToken";
	public static final String NULL_CHANGE = "";
	public static final String APP_ID = "appId";
	public static final String PRE = "pre";
	public static final String POST = "post";
	public static final String ZERO = "0";
	public static final String SEPARATOR = ",";
	public static final String RETURN_CODE_DEFAULT = "200";
	// 日志批量入库时一次入库的数量
	public static final int PRE_COMMIT = 100;
	// 最大重试次数
	public static final int MAX_TRY_TIMES = 3;
	// 待审核
	public static final int API_DOMAIN_STATUS_PENDING = 0;
	// 审核退回
	public static final int API_DOMAIN_STATUS_REJECT = 2;
	// 域下审核通过
	public static final int API_DOMAIN_STATUS_OK = 3;
	// 关闭
	public static final int API_DOMAIN_STATUS_CLOSE = 4;
	// 不需要加载到网关
	public static final int NO_NEED_LOAD = -1;
	// 接入时的token
	public static final String APP_API_TOKEN_KEY = "TGIT_GATEWAY";
	// 存储API的访问URI与API之间的对应关系
	public static final String API_ACCESSURI_CACHE_KEY = "api_accessuri";
	// 字符串之间的连接符
	public static final String SYMBOL = "_";
	// 存储到网关缓存中的KEY前缀
	public static final String GATEWAY_PRE_KEY = "TGIT_";
	// 存储到网关缓存中的DELOPY前缀
	public static final String GATEWAY_DEPLOY_KEY = "_deploy";
	/**
	 * ******************************reqErrorCode 详情：
	 * *******************100-API未注册 *******************101-API关闭
	 * *******************102-API使用时间过期 ***************103-API未启用
	 * *******************104-API所有服务器为空 **************105-apiId解析异常
	 * *******************106-部署url为空 ******************107-请求体的数据为空
	 * *******************108-鉴权信息为空  ******************109-鉴权信息不存在或者不匹配	
	 * *******************110-API并发量超限*****************111-部署URL格式错误
	 * *******************112-报文格式错误或报文内容解析错误  ******113-网关并发限流异常处理
	 * *******************114-地址不通熔断返回                              ******115-
	 */
	public static final String REQ_ERROR_CODE_100 = "100";
	public static final String REQ_ERROR_CODE_101 = "101";
	public static final String REQ_ERROR_CODE_102 = "102";
	public static final String REQ_ERROR_CODE_103 = "103";
	public static final String REQ_ERROR_CODE_104 = "104";
	public static final String REQ_ERROR_CODE_105 = "105";
	public static final String REQ_ERROR_CODE_106 = "106";
	public static final String REQ_ERROR_CODE_107 = "107";
	public static final String REQ_ERROR_CODE_108 = "108";
	public static final String REQ_ERROR_CODE_109 = "109";
	public static final String REQ_ERROR_CODE_110 = "110";
	public static final String REQ_ERROR_CODE_111 = "111";
	public static final String REQ_ERROR_CODE_112 = "112";
	public static final String REQ_ERROR_CODE_113 = "113";
	public static final String REQ_ERROR_CODE_114 = "114";
	public static final Map<String,String> ERROR_MAP=new ConcurrentHashMap<String,String>();
	/**
	 * ********************************returnCode 详情： *******************200-正常
	 * *******************404-未找到 405-状态允许 *******************401-API未授权
	 */
	public static final String RETURN_CODE_401 = "401";
	public static final String RETURN_CODE_404 = "404";
	public static final String RETURN_CODE_405 = "405";
	public static final String RETURN_CODE_503 = "503";
	/**
	 * 
	 */
	public static final String SUCCESS = "0";
	// 当前网络无法连接
	public static final String NET_CONNECT_ERROR = "NET_CONNECT_ERROR";
	// 发送消息失败
	public static final String SEND_MSG_ERROR = "SEND_MSG_ERROR";
	// FTP无法连接的错误
	public static final String FTP_CONNECT_ERROR = "FTP_CONNECT_ERROR";
	// URL格式错误
	public static final String PARAM_FORMAT_ERROR = "PARAM_FORMAT_ERROR";
	// 指定目录下没有文件
	public static final String FILES_NOT_EXIST = "FILES_NOT_EXIST";
	// 数据库连接失败
    public static final String DB_CONNECT_ERROR = "DB_CONNECT_ERROR";
    // 依赖数据还未同步
    public static final String MISS_REL_DATA = "MISS_REL_DATA";
    // Redis还未连接
    public static final String REDIS_CONNECT_FAIL = "REDIS_CONNECT_FAIL";
    // 系统内部错误，请联系管理员
    public static final String UNKNOW_ERROR = "UNKNOW_ERROR";
    // 业务系统异常
    public static final String BUSSERROR = "BUSSERROR";
    // 网关缓存数据异常
    public static final String GATEWAY_ERROR= "GATEWAY_ERROR";
	static {
		ERROR_MAP.put(REQ_ERROR_CODE_100, "API未注册");
		ERROR_MAP.put(REQ_ERROR_CODE_101, "API已关闭");
		ERROR_MAP.put(REQ_ERROR_CODE_102, "API使用时间过期");
		ERROR_MAP.put(REQ_ERROR_CODE_103, "API未启用");
		ERROR_MAP.put(REQ_ERROR_CODE_104, "API所有服务器为空");
		ERROR_MAP.put(REQ_ERROR_CODE_105, "APIID数据解析异常");
		ERROR_MAP.put(REQ_ERROR_CODE_106, "部署url为空");
		ERROR_MAP.put(REQ_ERROR_CODE_107, "请求体的数据为空");
		ERROR_MAP.put(REQ_ERROR_CODE_108, "鉴权信息为空");
		ERROR_MAP.put(REQ_ERROR_CODE_109, "鉴权信息不存在或者不匹配");
		ERROR_MAP.put(REQ_ERROR_CODE_110, "API并发量超限");
		ERROR_MAP.put(REQ_ERROR_CODE_111, "部署URL格式错误");
		ERROR_MAP.put(REQ_ERROR_CODE_112, "报文格式错误或报文内容解析错误");
		ERROR_MAP.put(REQ_ERROR_CODE_113, "网关并发限流异常处理");
		ERROR_MAP.put(REQ_ERROR_CODE_114, "地址不通熔断返回  ");
		ERROR_MAP.put(RETURN_CODE_401, "API未授权");
		ERROR_MAP.put(RETURN_CODE_404, "客户端错误");
		ERROR_MAP.put(RETURN_CODE_405, "状态允许");
		ERROR_MAP.put(RETURN_CODE_503, "网关错误");
		ERROR_MAP.put(SUCCESS,"成功");
		ERROR_MAP.put(NET_CONNECT_ERROR,"当前网络无法连接");
		ERROR_MAP.put(SEND_MSG_ERROR,"发送消息失败");
		ERROR_MAP.put(PARAM_FORMAT_ERROR,"参数格式错误");
		ERROR_MAP.put(FTP_CONNECT_ERROR,"FTP连接失败");
		ERROR_MAP.put(FILES_NOT_EXIST,"指定的目录下没有文件");
		ERROR_MAP.put(DB_CONNECT_ERROR, "数据库连接失败");
		ERROR_MAP.put(MISS_REL_DATA, "依赖数据还未同步");
		ERROR_MAP.put(REDIS_CONNECT_FAIL, "Redis缓存服务器未连接");
		ERROR_MAP.put(UNKNOW_ERROR, "系统内部错误，请联系管理员");
		ERROR_MAP.put(BUSSERROR, "业务异常");
		ERROR_MAP.put(GATEWAY_ERROR, "网关缓存数据异常");
	}
	
	/**
	 * 
	* @ClassName: ROUTE_CHANNE   
	* @Description: TODO(这里用一句话描述这个类的作用)   
	* @author fanzaijun 
	* @date 2018年10月31日 下午4:14:33   
	*
	 */
	public static class ROUTE_CHANNE{
		public static final String PREFIX_PATH="PrefixPath";
		public static final String SET_PATH="SetPath";
		public static final String REQUEST_RATE_LIMITER="RequestRateLimiter";
		public static final String PATH="Path";
		public static final String METHOD="Method";
		public static final String PRE_ERROR="PreError";
		public static final String NET_LIMIT="NetLimit";
	}
	
	/**
	 * 
	* @ClassName: GATEWAY_API   
	* @Description: 网关API状态枚举 
	* @author fanzaijun 
	* @date 2018年10月31日 下午4:14:38   
	*
	 */
	public static class GATEWAY_API{
		// 正常
	    public static final int STATUS_NORMAL = 0;
	    // 关闭
	    public static final int STATUS_CLOSE = 1;
	    // 过期
	    public static final int STATUS_EXPIRE = 2;
	    // 还未使用
	    public static final int STATUS_NOT_USED = 3;
	    // 所有关联的服务器都停止
	    public static final int STATUS_NO_SERVER = 4;
	}
	/**
	 * 
	* @Title: getErrorMsg   
	* @Description: 通过CODE获取MSG
	* @author fanzaijun  
	* @date 2018年10月25日 下午3:40:51   
	* @param code
	* @return  
	* String  
	* @throws (没有异常抛出)
	 */
	public static String getErrorMsg(String code){
		String msg = ERROR_MAP.get(code);
		if (CommonUtil.isEmpty(msg)){
			return code;
		}
		return msg;
	}
}
